import { useState, useEffect } from "react";
import { loadCategoriesAPI, loadMedicinesAPI } from "../services/medicine";
import { dalImg } from "../utils/tools";

/**
 * 自定一个hooks
 * @returns
 */
export function useMedicineData() {
  const [banners, setBanners] = useState([]);
  const [categories, setCategories] = useState([]);
  useEffect(() => {
    // 初始化的时候获取数据
    loadMedicinesAPI().then((res) => {
      // console.log(res.data.list);

      setBanners(banners.concat(res.data.list));
    });
    loadCategoriesAPI().then((res) => {
      setCategories(res.data);
    });
  }, []);

  return { banners, categories };
}
